package com.xydtech.web.controller.system;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.DateUtils;
import com.xydtech.system.domain.SysLoanConfiguration;
import com.xydtech.system.service.ISysLoanConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <dd>描述: ~ 贷款计算器参数配置Controller</dd>
 * <dd>创建时间：  16:37 2024/1/20</dd>
 * <dd>创建人： yuzhiguo</dd>
 * <dt>版本历史: </dt>
 * Date         Author         Version     Description
 * ------------------------------------------------------------------
 * 2024/1/20     yuzhiguo         1.0        1.0 Version
 */
@Controller
@RequestMapping("/system/configuration")
public class SysLoanConfigurationController extends BaseController {
    private String prefix = "system/calculator";

    @Autowired
    private ISysLoanConfigurationService sysLoanConfigurationService;

    /**
     * 跳转个人额度计算配置页
     * @param loanId
     * @param mmap
     * @return
     */
    @GetMapping("loanConfiguration/{loanId}")
    public String loanConfiguration(@PathVariable("loanId") String loanId, ModelMap mmap)
    {
        SysLoanConfiguration sysLoanConfiguration = sysLoanConfigurationService.selectSysLoanConfigurationByLoanId(loanId);
        mmap.put("sysLoanConfiguration", sysLoanConfiguration);
        return prefix + "/loanConfiguration";
    }

    /**
     * 跳转个体工商户额度计算配置页
     * @param loanId
     * @param mmap
     * @return
     */
    @GetMapping("loanIndividuality/{loanId}")
    public String loanIndividuality(@PathVariable("loanId") String loanId, ModelMap mmap)
    {
        SysLoanConfiguration sysLoanConfiguration = sysLoanConfigurationService.selectSysLoanConfigurationByLoanId(loanId);
        mmap.put("sysLoanConfiguration", sysLoanConfiguration);
        return prefix + "/loanIndividuality";
    }

    /**
     * 修改保存额度计算配置页
     */
    @Log(title = "修改保存额度计算配置页", businessType = BusinessType.UPDATE)
    @PostMapping("/editLoanConfiguration")
    @ResponseBody
    public AjaxResult editLoanConfiguration(SysLoanConfiguration sysLoanConfiguration) {
        sysLoanConfiguration.setUpdateBy(getLoginName());
        sysLoanConfiguration.setUpdateTime(DateUtils.formatDate(new Date(),DateUtils.YYYY_MM_DD_HH_MM_SS));
        return toAjax(sysLoanConfigurationService.editLoanConfiguration(sysLoanConfiguration));
    }
}
